package com.gimi.cloud.jimi.queue.revicer;

import com.gimi.cloud.jimi.common.mq.enume.QueueConstant;
import com.gimi.cloud.jimi.dao.dao.sys.SysMqLogDao;
import com.gimi.cloud.jimi.entity.sys.SysMqLogEntity;
import com.gimi.cloud.jimi.dto.params.SocialSecurityParam;
import com.gimi.cloud.jimi.queue.service.FengchaoShebaoService;
import com.gimi.cloud.jimi.queue.service.impl.FengchaoShebaoServiceImpl;
import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

@Component
public class FengchaoShebaoReceived {

    private static final Logger logger = LoggerFactory.getLogger(FengchaoShebaoServiceImpl.class);
    private FengchaoShebaoService fengchaoShebaoService;
    SysMqLogDao sysMqLogDao;


    @Autowired
    public FengchaoShebaoReceived(FengchaoShebaoService fengchaoShebaoService,SysMqLogDao sysMqLogDao) {
        this.fengchaoShebaoService = fengchaoShebaoService;
        this.sysMqLogDao = sysMqLogDao;
    }

    /**
     * 获取蜂巢社保队列
     *
     * @param message
     * @param channel
     * @throws IOException
     */
    @RabbitListener(queues = {QueueConstant.FCSB_QUEUE_NAME})
    public void reveiveOperationLog(Message message, Channel channel, SocialSecurityParam socialSecurityParam) throws IOException {
        logger.info("消息队列，获取蜂巢社保队列开始,入参："+socialSecurityParam);
        SysMqLogEntity mqLog = new SysMqLogEntity();
        mqLog.setName("获取蜂巢社保队列");
        mqLog.setStartTime(new Date());
        mqLog.setUserId(socialSecurityParam.getOperUserId());
        mqLog.setParam(socialSecurityParam.toString());
        fengchaoShebaoService.reveiveSheBaoData(message, channel, socialSecurityParam);
        mqLog.setEndTime(new Date());
        sysMqLogDao.insertSelective(mqLog);
        logger.info("消息队列，获取蜂巢社保队列结束");
    }
}
